package com.gogowan.agroenterprise.widget.adapter;

import java.util.List;

import com.gogowan.agroenterprise.R;
import com.gogowan.agroenterprise.model.BoxCodeMaterial;
import com.gogowan.agroenterprise.utils.Utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class InOutDetailAdapter extends BaseAdapter {

	private Context context;
	private List<BoxCodeMaterial> datas;

	public InOutDetailAdapter(Context context, List<BoxCodeMaterial> datas) {
		this.context = context;
		this.datas = datas;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datas.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.layout_inout_details_item, null);
			viewHolder.cpbh = (TextView) convertView.findViewById(R.id.cpbh);
			viewHolder.cpmc = (TextView) convertView.findViewById(R.id.cpmc);
			viewHolder.msl = (TextView) convertView.findViewById(R.id.msl);
			viewHolder.ewmbm = (TextView) convertView.findViewById(R.id.ewmbm);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.cpbh.setText((Utils.isEmpty(datas.get(position).getMaterialSpec() + "")?datas.get(position).getMaterialSpection()+"":datas.get(position).getMaterialSpec() + ""));
		viewHolder.cpmc.setText(datas.get(position).getMaterialName() + "");
		viewHolder.msl.setText(datas.get(position).getMaCount() + "");
		viewHolder.ewmbm.setText((Utils.isEmpty(datas.get(position).getEwmCode()+ "")? datas.get(position).getEwm()+ "":datas.get(position).getEwmCode()+""));
		return convertView;
	}

	static class ViewHolder {
		TextView cpbh;
		TextView cpmc;
		TextView msl;
		TextView ewmbm;
	}

}
